package com.nkzy.controller;

import com.nkzy.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import sun.plugin.dom.core.Element;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Create by 王建烨 on 2022/4/8 11:06
 **/

@Controller
public class PageController {
    @GetMapping("/show")
    public String showPage(Model model, HttpServletRequest request){
        model.addAttribute("msg", "666 Thymeleaf");
        model.addAttribute("date",new Date());
        User user = new User("张三","男","19");
        model.addAttribute("user",user);
        model.addAttribute("sex","男");
        model.addAttribute("id",100);
        model.addAttribute("name","陈佳鑫");
        List<User> userList = new ArrayList();
        for (int i = 0; i < 10; i++) {
            userList.add(new User("user_"+i,"男",(19+i)+""));
        }
        model.addAttribute("userList",userList);
        Map<String,User> userMap = new HashMap();
        for (int i = 0; i < 10; i++) {
            userMap.put("user"+i,new User("user_"+i,"男",(19+i)+""));
        }
        model.addAttribute("userMap",userMap);
        request.setAttribute("req","Http Servlet Request");
        request.getSession().setAttribute("seq","Http Session");
        request.getSession().getServletContext().setAttribute("app","application");
        return "index";
    }

    @GetMapping("/show2")
    public String showPage2(String id,String name){
        System.out.println(id+"\t"+name);
        return "index2";
    }

    @GetMapping("show3/{id}")
    public String showPage3(@PathVariable String id){
        System.out.println(id);
        return "index2";
    }

    @GetMapping("show4/{id}/{name}")
    public String showPage4(@PathVariable String id,@PathVariable String name){
        System.out.println(id+"\t"+name);
        return "index2";
    }

    @GetMapping("show5/{id}")
    public String showPage5(@PathVariable String id,String name){
        System.out.println(id+"\t"+name);
        return "index2";
    }
}
